#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=105;
double x[N];
double y[N];
int main(void){
    int t;
    scanf("%d",&t);
    char c;
    int n;
    while(t--){
        int t;
        getchar();
        scanf("%c %d",&c,&n);
        if(c>='A' && c<='Z'){
            t=c-'A'+1+n;
            printf("%d\n",t);
        }
        else{
            t=(c-'a'+1)*-1+n;
            printf("%d\n",t);
        }
    }
    return 0;
}
